﻿using System;
using System.ComponentModel.DataAnnotations;
using GC_RF.BusinessEntities.DTOs;
using GC_RF.Domain.Constants;
using GC_RF.Site.Resources.Constants;

namespace GC_RF.Site.Models.News
{
	public class NewsModel
	{
		#region Variables

		private string _preview;

		#endregion

		#region Properties

		public int Id { get; set; }

		[Display(Name = "Изображение")]
		public string ImageUrl { get; set; }

		[Display(Name = "Ссылка на изображение")]
		public string StaticImageUrl { get; set; }

		[Display(Name = "Заголовок")]
		public string Title { get; set; }

		public string ShortTitle
		{
			get
			{
				return string.IsNullOrWhiteSpace(Title) || Title.Length <= UIHelper.MaxShortNewsTitleCharacterCount
					? Title
					: string.Format(Templates.ShortText, Title.Substring(0, UIHelper.MaxShortNewsTitleCharacterCount));
			}
		}

		[Display(Name = "Текст новости")]
		public string Description { get; set; }

		[Display(Name = "Текст превью")]
		public string Preview
		{
			get
			{
				return string.IsNullOrWhiteSpace(_preview) || _preview.Length <= UIHelper.MaxShortNewsPreviewCharacterCount
					? _preview
					: string.Format(Templates.ShortText, _preview.Substring(0, UIHelper.MaxShortNewsPreviewCharacterCount));
			}
			set { _preview = value; }
		}

		public DateTime DateCreated { get; set; }

		public string Date
		{
			get { return DateCreated.ToShortDateString(); }
		}

		#endregion

		#region Constructors

		public NewsModel() { }

		public NewsModel(NewsData data)
		{
			if (data == null) return;

			Title = data.Title;
			Description = data.Description;
			_preview = data.Preview;
			Id = data.Id;
			DateCreated = data.Date;
			ImageUrl = StaticImageUrl = data.ImageUrl;
		}

		#endregion
	}
}